package org.idea.iedis.framework.server.io.core.bio;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @Author linhao
 * @Date created in 11:17 上午 2021/8/15
 */
public class BioClient {

    public static final ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(2, 5,
            0L, TimeUnit.MILLISECONDS,
            new LinkedBlockingQueue<Runnable>());

    public static void main(String[] args) {
        for (int i = 0; i < 5; i++) {
            Thread t = new Thread(new Runnable() {
                @Override
                public void run() {
                    Socket socket = new Socket();
                    try {
                        socket.connect(new InetSocketAddress("localhost", 6378));
                        socket.getOutputStream().write("this is test".getBytes());
                        System.out.println("send data -----------" + System.currentTimeMillis());
                        socket.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            });
            threadPoolExecutor.submit(t);
        }
        Thread.yield();
    }
}
